<?php
$funcNum = @$_GET['CKEditorFuncNum'] ;
//文件上传
if(!empty($_FILES['upload']))
{
	
	
    
	$path =  uploader($_FILES['upload']);
	$message = '上传成功!';
	echo "<script type='text/javascript'>window.parent.CKEDITOR.tools.callFunction($funcNum, '$path', '$message');</script>";
}
else  //文件列表
{
	$list = getFileList('./uploads/');
	print_r($list);

}


//文件上传
	function uploader($file,$new_dir='./uploads/',$resize=flse,$remove=false){
		
		if(!file_exists($new_dir))
		{
			mkdir($new_dir);
		}
		$tempFile = $file['tmp_name'];
			
		$name = $file['name'];
		$info = pathinfo($name);
		$md5 = md5($info['filename'].time());
		$md5 = substr($md5,0 ,10);
		$file_name = $md5.'.'.strtolower($info['extension']);
		$new_name =$new_dir. '' . $file_name;//上传后的图片路径
			
		//$fileTypes = array('jpg','jpeg','gif','png','pdf','doc','docx','xls','xlsx','mov','3gp','mp4'); //允许的文件后缀
		$imgTypes = array('jpg','jpeg','gif','png'); //图片类型
			
			
		move_uploaded_file($tempFile,$new_name);
		
		return  $new_name;//上传成功后返回给前端的数据
	}

//取得文件和目录数组
function getFileList($path){
	$dir_list = array();
	$file_list= array();
	foreach(new DirectoryIterator($path) as $key=>$val)
	{
		if(!is_dir($val))
		{
			$new_path = $path.$val;
			
			if(is_file($new_path))
			{
				$file_list[] = $new_path;	
			}
			else
			{
				$dir_list[] = $new_path;	
			}
		}
	}
	$result = array('file'=>$file_list,'dir'=>$dir_list);

	return $result;	
}
?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<SCRIPT language=JavaScript>

// 获取地址参数
function getUrlParam(paramName)
{
  var reParam = new RegExp('(?:[\?&]|&amp;)' + paramName + '=([^&]+)', 'i') ;
  var match = window.location.search.match(reParam) ;
  return (match && match.length > 1) ? match[1] : '' ;
}

function ReturnImg(reimg)
{
    var funcNum = getUrlParam('CKEditorFuncNum');
	if(funcNum > 1)
	{
		var fileUrl = reimg;
		window.opener.CKEDITOR.tools.callFunction(funcNum, fileUrl);
	}
	if(window.opener.document.<?php echo $f?> != null)
	{
		window.opener.document.<?php echo $f?>.value=reimg;
		if(window.opener.document.getElementById('div<?php echo $v?>'))
	    {
		 if(TNav()=='IE'){
			 //window.opener.document.getElementById('div<?php echo $v?>').filters.item('DXImageTransform.Microsoft.AlphaImageLoader').src = reimg;
			 window.opener.document.getElementById('div<?php echo $v?>').src = reimg;
			 window.opener.document.getElementById('div<?php echo $v?>').style.width = '150px';
			 window.opener.document.getElementById('div<?php echo $v?>').style.height = '100px';
		 }
		 else
			 window.opener.document.getElementById('div<?php echo $v?>').style.backgroundImage = "url("+reimg+")";
	  }
		else if(window.opener.document.getElementById('<?php echo $v?>')){
			window.opener.document.getElementById('<?php echo $v?>').src = reimg;
		}
		if(document.all) window.opener=true;
	}
	
    window.close();
}
</SCRIPT>